import 'package:json_annotation/json_annotation.dart';

part 'offers.g.dart';

@JsonSerializable()
class Offers {
  int id;

  int storeId;

  int userId;

  int type;

  //优惠类型，1：整单折扣，2：方案折扣，3：满减，4：特价菜，5：相同菜品第二份优惠，6：买赠
  int discountType;

  String get discountTypeString {
    Map<int, String> map = {
      1: '整单折扣',
      2: '方案折扣',
      3: '满减',
      4: '特价菜',
      5: '第二份优惠',
      6: '买赠',
    };

    return map[discountType];
  }

  String activityName;

  int activityType;

  String startDate;

  String endDate;

  String startTime;

  String endTime;

  String weekTime;

  int status;

  int supportQrcode;

  String ctime;

  String utime;

  List<OrderDiscountList> orderDiscountList;

  int get orderDiscountCount {
    if (orderDiscountList[0].commodityId == 0) {
      return 0;
    }

    return orderDiscountList.length;
  }

  List<PlanMenuDiscount> planMenuDiscountList;

  List<FullDiscount> fullDiscountList;

  List<FoodDiscount> foodDiscountList;

  int get foodDiscountCount {
    if (foodDiscountList[0].commodityId == 0) {
      return 0;
    }
    return foodDiscountList.length;
  }

  List<SecondDiscount> secondDiscountList;

  List<BuyDiscount> buyGiveDiscountlist;

  Offers(
    this.id,
    this.storeId,
    this.userId,
    this.type,
    this.discountType,
    this.activityName,
    this.activityType,
    this.startDate,
    this.endDate,
    this.startTime,
    this.endTime,
    this.weekTime,
    this.status,
    this.supportQrcode,
    this.ctime,
    this.utime,
    this.orderDiscountList,
    this.planMenuDiscountList,
  );

  factory Offers.fromJson(Map<String, dynamic> srcJson) => _$OffersFromJson(srcJson);

  Map<String, dynamic> toJson() => _$OffersToJson(this);
}

@JsonSerializable()
class OrderDiscountList {
  int id;

  int storeId;

  int userId;

  int discountId;

  int discountRate;

  int commodityId;

  int skuId;

  String ctime;

  String utime;

  String discountName;

  ComPropertiesDTO comPropertiesDTO;

  OrderDiscountList(
    this.id,
    this.storeId,
    this.userId,
    this.discountId,
    this.discountRate,
    this.commodityId,
    this.skuId,
    this.ctime,
    this.utime,
    this.discountName,
    this.comPropertiesDTO,
  );

  factory OrderDiscountList.fromJson(Map<String, dynamic> srcJson) => _$OrderDiscountListFromJson(srcJson);

  Map<String, dynamic> toJson() => _$OrderDiscountListToJson(this);
}

@JsonSerializable()
class ComPropertiesDTO {
  int commodityId;

  int skuId;

  int price;

  int memberPrice;

  String images;

  int stock;

  String title;

  String specText;

  String commoditySkuName;

  String unit;

  String get commodityAndSkuName {
    return commoditySkuName == '' ? title : '$title($commoditySkuName)';
  }

  ComPropertiesDTO(
    this.commodityId,
    this.skuId,
    this.price,
    this.memberPrice,
    this.images,
    this.stock,
    this.title,
    this.specText,
    this.commoditySkuName,
    this.unit,
  );

  factory ComPropertiesDTO.fromJson(Map<String, dynamic> srcJson) => _$ComPropertiesDTOFromJson(srcJson);

  Map<String, dynamic> toJson() => _$ComPropertiesDTOToJson(this);
}

@JsonSerializable()
class PlanMenuDiscount {
  int id;

  int discountId;

  int storeId;

  int userId;

  int menuId;

  String menuName;

  int discountRate;

  String ctime;

  String utime;

  String discountName;

  int count;

  PlanMenuDiscount(
    this.id,
    this.discountId,
    this.storeId,
    this.userId,
    this.menuId,
    this.discountRate,
    this.ctime,
    this.utime,
    this.discountName,
    this.menuName,
    this.count,
  );

  factory PlanMenuDiscount.fromJson(Map<String, dynamic> srcJson) => _$PlanMenuDiscountFromJson(srcJson);

  Map<String, dynamic> toJson() => _$PlanMenuDiscountToJson(this);
}

@JsonSerializable()
class FullDiscount extends Object {
  int id;

  int storeId;

  int userId;

  int discountId;

  int fullCount;

  int reductionCount;

  String ctime;

  String utime;

  String discountName;

  FullDiscount(
    this.id,
    this.storeId,
    this.userId,
    this.discountId,
    this.fullCount,
    this.reductionCount,
    this.ctime,
    this.utime,
    this.discountName,
  );

  factory FullDiscount.fromJson(Map<String, dynamic> srcJson) => _$FullDiscountFromJson(srcJson);

  Map<String, dynamic> toJson() => _$FullDiscountToJson(this);
}

@JsonSerializable()
class FoodDiscount extends Object {
  int id;

  int storeId;

  int userId;

  int discountId;

  int discountRate;

  int commodityId;

  int skuId;

  String ctime;

  String utime;

  String discountName;

  String unit;

  ComPropertiesDTO comPropertiesDTO;

  FoodDiscount(
    this.id,
    this.storeId,
    this.userId,
    this.discountId,
    this.discountRate,
    this.commodityId,
    this.skuId,
    this.ctime,
    this.utime,
    this.discountName,
  );

  factory FoodDiscount.fromJson(Map<String, dynamic> srcJson) => _$FoodDiscountFromJson(srcJson);

  Map<String, dynamic> toJson() => _$FoodDiscountToJson(this);
}

@JsonSerializable()
class SecondDiscount extends Object {
  int id;

  int storeId;

  int userId;

  int discountId;

  int secondType;

  int discountRate;

  int reductionCount;

  int commodityId;

  int skuId;

  String ctime;

  String utime;

  String discountName;

  ComPropertiesDTO comPropertiesDTO;

  SecondDiscount(
    this.id,
    this.storeId,
    this.userId,
    this.discountId,
    this.secondType,
    this.discountRate,
    this.reductionCount,
    this.commodityId,
    this.skuId,
    this.ctime,
    this.utime,
    this.discountName,
    this.comPropertiesDTO,
  );

  factory SecondDiscount.fromJson(Map<String, dynamic> srcJson) => _$SecondDiscountFromJson(srcJson);

  Map<String, dynamic> toJson() => _$SecondDiscountToJson(this);
}

@JsonSerializable()
class BuyDiscount extends Object {
  int id;

  int storeId;

  int userId;

  int discountId;

  int buyCount;

  int giveCount;

  int commodityId;

  int skuId;

  int giveCommodityId;

  int giveSkuId;

  String ctime;

  String utime;

  String discountName;

  ComPropertiesDTO buyComPropertiesDTO;

  ComPropertiesDTO giveComPropertiesDTO;

  BuyDiscount(
    this.id,
    this.storeId,
    this.userId,
    this.discountId,
    this.buyCount,
    this.giveCount,
    this.commodityId,
    this.skuId,
    this.giveCommodityId,
    this.giveSkuId,
    this.ctime,
    this.utime,
    this.discountName,
    this.buyComPropertiesDTO,
    this.giveComPropertiesDTO,
  );

  factory BuyDiscount.fromJson(Map<String, dynamic> srcJson) => _$BuyDiscountFromJson(srcJson);

  Map<String, dynamic> toJson() => _$BuyDiscountToJson(this);
}
